<template>
  <a-modal
    class="add-modal"
    :visible="addVisible"
    :maskClosable="false"
    :destroyOnClose="true"
    :keyboard="false"
    title="文案分类"
    :footer="null"
    @cancel="closeModal(false)"
    width="700px"
  >
    <search-table
      :url="url"
      ref="searchtable"
      :columns="columns"
      :hideSelect="true"
    >
      <template slot="oprationRow">
        <a-button type="primary" icon="plus" @click="addClass"
          >新增分类</a-button
        >
      </template>

      <template slot="tableOperation" slot-scope="{ record }">
        <a-space>
          <a
            href="javascript:;"
            class="text-primary pointer"
            @click="seeTextDetail(record)"
            >编辑</a
          >
          <a
            href="javascript:;"
            class="text-primary pointer"
            @click="delTextClassify(record.id)"
            >删除</a
          >
        </a-space>
      </template>
    </search-table>
    <addTextClassifyModal
      ref="addTextClassifyModal"
      @refresh="refresh"
      :record="record"
    ></addTextClassifyModal>
  </a-modal>
</template>
<script>
import addTextClassifyModal from "@/views/menuPage/gallery/contentManagement/posterManage/stencils/components/components/text/addTextClassifyModal";
export default {
  name: "TextClassify",
  components: { addTextClassifyModal },
  props: {
    addVisible: {
      // 是否显示弹窗
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      // form: this.$form.createForm(this, { name: 'table_search' }),
      url: "goldenhome/gh/poster_admin/copywriting/category/page",
      columns: [
        {
          title: "分类名称",
          dataIndex: "name",
          key: "name",
          align: "center",
        },
        {
          title: "排序",
          dataIndex: "sort",
          key: "sort",
          align: "center",
        },
        {
          title: "操作",
          dataIndex: "operation",
          fixed: "right",
          scopedSlots: { customRender: "operation" },
        },
      ],
      record: {},
    };
  },
  methods: {
    // 查看文案详情
    seeTextDetail(row) {
      this.record = row;
      this.$refs.addTextClassifyModal.visible = true;
    },
    // 删除文案分类
    delTextClassify(id) {
      this.$confirm({
        title: "删除提示",
        content: "删除后不可恢复,确认删除",
        onOk: async () => {
          await this.$post(
            "goldenhome/gh/poster_admin/copywriting/category/delete",
            { id: id }
          );
          this.refresh();
        },
      });
    },
    addClass() {
      this.record = {};
      this.$refs.addTextClassifyModal.visible = true;
    },
    // 关闭弹窗
    closeModal(bool) {
      this.$emit("cancel", bool);
    },
    // 刷新页面
    refresh() {
      this.$refs.searchtable.refreshTable();
    },
  },
};
</script>
<style lang="less" scoped>
</style>
